#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->horizontalSlider->setMaximum(1600);
    ui->horizontalSlider->setMinimum(800);
    ui->verticalSlider->setMaximum(1200);
    ui->verticalSlider->setMinimum(600);

    ui->horizontalSlider->setValue(800);
    ui->verticalSlider->setValue(600);

    ui->horizontalSlider->setSingleStep(100);
    ui->verticalSlider->setSingleStep(100);

    QShortcut* sc1 = new QShortcut(this);
    sc1->setKey(QKeySequence("-"));
    QShortcut* sc2 = new QShortcut(this);
    sc2->setKey(QKeySequence("+"));

    connect(sc1,&QShortcut::activated,this,&Widget::subValue);
    connect(sc2,&QShortcut::activated,this,&Widget::addValue);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::addValue()
{
    ui->horizontalSlider_2->setValue(ui->horizontalSlider_2->value()+10);
}

void Widget::subValue()
{
    ui->horizontalSlider_2->setValue(ui->horizontalSlider_2->value()-10);
}



void Widget::on_horizontalSlider_valueChanged(int value)
{
    QRect rect = this->geometry();
    this->setGeometry(rect.x(),rect.y(),value,rect.height());
}

void Widget::on_verticalSlider_valueChanged(int value)
{
    QRect rect = this->geometry();
    this->setGeometry(rect.x(),rect.y(),rect.width(),value);
}

void Widget::on_horizontalSlider_2_valueChanged(int value)
{
    ui->label->setText("当前数值为："+QString::number(value));
}
